﻿@{
    ViewBag.Title = "newindex";

}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/miniui/core.js")" type="text/javascript"></script>
    <link rel="stylesheet" href="../Scripts/kindeditor-4.1.10/themes/default/default.css" />
    <script charset="utf-8" src="../Scripts/kindeditor-4.1.10/kindeditor-all.js"></script>
    <script charset="utf-8" src="../Scripts/kindeditor-4.1.10/lang/zh_CN.js"></script>
    <link href="~/Scripts/miniui/themes/default/large-mode.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        body {
            font-size:11pt !important;
        }
    </style>
}
<form id="form1" method="post">
    @Html.Partial("~/Views/Modular/Toolbars.cshtml")
    <table style="width: 620px; margin-top: 25px; margin-left: 20px">
        <tr>
            <td width="100px" height="35px" align="right">分类编码：</td>
            <td width="200px" height="35px">
                <input name="FNumber" id="FNumber" class="mini-textbox" style="width: 200px;" value="" tabindex="1"/>
            </td>
            <td width="120px" height="35px" align="right">图片URL：</td>
            <td width="200px" height="35px">
                <input name="FIcon" id="FIcon" readonly="true" class="mini-textbox" style="width: 200px;" />
            </td>
        </tr>
        <tr>
            <td width="100px" height="35px" align="right">所属大类：</td>
            <td width="200px" height="35px">
                @Html.Partial("~/Views/Modular/LookupGoodsClassTop.cshtml")
            </td>
            <td width="120px" height="35px" align="right"></td>
            <td rowspan="3">
                <img id="Image0" src="~/Content/Images/NoImage.jpg" width="190" height="120" />
            </td>
        </tr>
        <tr>
            <td width="100px" height="35px" align="right">分类名称：</td>
            <td width="200px" height="35px">
                <input name="FName" id="FName" class="mini-textbox" style="width: 200px;" tabindex="2" />
            </td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td width="100px" height="35px" align="right">商品类型：</td>
            <td width="200px" height="35px">
                <input id="FFreshType" name="FFreshType" class="mini-combobox" style="width:200px;" showNullItem="false" 
                    allowInput="false" align="left" value ="0" data ="comFresh" tabindex="3"/> 
            </td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td width="100px" height="35px" align="right">生鲜标识：</td>
            <td width="200px" height="35px">
                <input id="FScaleNo" name="FScaleNo" class="mini-combobox" style="width:200px;" showNullItem="false" 
                    allowInput="false" align="left" value ="21" data ="dScaleNo" tabindex="3"/> 
            </td>
            <td></td>
            <td></td>
        </tr>
       <tr>
            <td width="100px" height="35px" align="right">分类备注：</td>
            <td width="200px" height="35px">
                <input name="FRemark" id="FRemark" class="mini-textbox" style="width: 200px;" tabindex="4" />
            </td>
            <td></td>
            <td></td>
        </tr>
       <tr>
            <td width="100px" height="35px" align="right"></td>
            <td width="200px" height="35px">
                带条码为普通产品称重为生鲜产品计件为称重按个卖产品
            </td>
            <td></td>
            <td></td>
        </tr>
    </table>
    <input id="FItemID" name="FItemID" class="mini-hidden" />
    <input id="FItemType" name="FItemType" class="mini-hidden" value="2" />
    <input id="FSystemAppID" name="FSystemAppID" class="mini-hidden" />
    <input id="CorpID" name="CorpID" class="mini-hidden" />
    <script type="text/javascript">
        var comFresh = [{ "id": "0", "text": "普通商品" },
                   { "id": "1", "text": "称重商品" },
                   { "id": "2", "text": "计件商品" },
                   { "id": "3", "text": "服务项目" }];

        var dScaleNo = [{ "id": "21", "text": "21" },
                   { "id": "99", "text": "99" }];

        var mAction = "new";

        //加载类别
        function SetClassData(data) {
            mAction = data.action;
            mini.getbyName("CorpID").setValue(data.FCorpID);
           if (data.action == "new") {
                //跨页面传递的数据对象，克隆后才可以安全使用
               mini.getbyName("FItemID").setValue('0');
               if (data.FClassID > 0) {
                   //mini.getbyName("FClassNumber").setValue(data.FClassID);
                   //mini.getbyName("FClassNumber").setText(data.FClassNumber);
                   //mini.getbyName("FGoodsClassName").setValue(data.FClassName);
                   var dataparam = "[{FItemID:" + data.FClassID + ", mSystemAppID:'" + parent.window.getSystemAppID() + "'}]";
                   $.post("../GoodClass/GetTopGoodsClass", { json: dataparam }, function (data) {
                       var mdata = mini.decode(data);
                       if (mdata.data.length > 0) {
                           mini.get("FClassNumber").setValue(mdata.data[0].FItemID);
                           mini.get("FClassNumber").setText(mdata.data[0].FNumber);
                           mini.get("FGoodsClassName").setValue(mdata.data[0].FName);
                       }
                   });
               }
               NewClass();
            }
            else {
                mini.getbyName("FItemID").setValue(data.FItemID);
                $.post("GetGoodClass", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                    var form = new mini.Form("form1");
                    var mdata = mini.decode(data);
                    mini.getbyName("FNumber").setValue(mdata.data[0].FNumber);
                    mini.getbyName("FName").setValue(mdata.data[0].FName);
                    mini.getbyName("FIcon").setValue(mdata.data[0].FIcon);
                    mini.getbyName("FRemark").setValue(mdata.data[0].FRemark);
                    mini.getbyName("FFreshType").setValue(mdata.data[0].FFreshType);
                    mini.getbyName("FScaleNo").setValue(mdata.data[0].FScaleNo);
                    if (mdata.data[0].FIcon != null) {
                        var path = ImageFilePath(mdata.data[0].FIcon);
                        $("#Image0").attr('src', path);
                    }
                    var dataparam = "[{FItemID:" + mdata.data[0].FParentID + ", mSystemAppID:'" + parent.window.getSystemAppID() + "'}]";
                    $.post("../GoodClass/GetGoodClassFatehr", { json: dataparam }, function (data) {
                        var mdata = mini.decode(data);
                        if (mdata.data.length > 0) {
                            mini.get("FClassNumber").setValue(mdata.data[0].FItemID);
                            mini.get("FClassNumber").setText(mdata.data[0].FNumber);
                            mini.get("FGoodsClassName").setValue(mdata.data[0].FName);
                        }
                    });
                });
            }
            mini.getbyName("FIcon").setEnabled(false);
        }


        //新增分类
        function NewClass() {
            mini.getbyName("FItemID").setValue("0");
            mini.getbyName("FName").setValue("");
            mini.getbyName("FRemark").setValue("");
            mini.getbyName("FIcon").setValue("");
            $("#Image0").attr("src", "http://localhost:13065/Content/Images/NoImage.jpg");
            var Fnumber = mini.getbyName("FClassNumber").getText();
            var FClassID = mini.getbyName("FClassNumber").getValue();
            if (FClassID == '')
                FClassID = '0';
            var mSystemAppID = parent.window.getSystemAppID();
            var jsonstr = '{FClassID:' + FClassID + ',FNumber:"' + Fnumber + '",mSystemAppID:"' + mSystemAppID + '"}';
            $.post('NewGoodsClass', { json: jsonstr }, function (data) {
                //var mdata = mini.decode(data);        
                mini.getbyName("FNumber").setValue(data);
            });
            mini.getbyName("FName").focus();
        }

        //保存分类
        function SaveInfo() {
            if (mini.getbyName("FName").getValue() == '') { mini.alert('分类名称不能为空'); return; }
            if (mini.getbyName("FNumber").getValue() == '') { mini.alert('分类编码不能为空'); return; }
            if ((mini.getbyName("FClassNumber").getValue() == mini.getbyName("FItemID").getValue())
                && (mini.getbyName("FItemID").getValue() != "") && (mini.getbyName("FItemID").getValue() != "0"))
            {
                mini.alert('所属分类不能为本分类');
                return;
            }
            if (isNaN(mini.getbyName("FNumber").getValue())) {
                mini.alert("编码中不能有字符，只能是数字");
                mini.getbyName("FNumber").focus();
                return false;
            }

            mini.getbyName("SaveInfo").disable();
            var form = new mini.Form("#form1");
            var data = form.getData(true, false);
            var json = mini.encode(data);
            var ClassID = (mini.getbyName("FClassNumber").getValue() == '' ? '0' : mini.getbyName("FClassNumber").getValue());
            json = "{ 'FClassNumber': '" + ClassID + "', 'FGoodsClassName': '" + mini.getbyName("FGoodsClassName").getValue()
                + "', 'FNumber': '" + mini.getbyName("FNumber").getValue() + "', 'FName': '" + mini.getbyName("FName").getValue()
                + "', 'FRemark': '" + mini.getbyName("FRemark").getValue() + "', 'FItemID': '" + mini.getbyName("FItemID").getValue()
                + "', 'FItemType': '" + mini.getbyName("FItemType").getValue() + "', 'FIcon': '" + mini.getbyName("FIcon").getValue()
                + "', 'FFreshType': '" + mini.getbyName("FFreshType").getValue() + "', 'FScaleNo': '" + mini.getbyName("FScaleNo").getValue() + "'}";
            $.post("../GoodClass/saveGoodClass", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                var ret = mini.decode(data);
                if (ret.status == 1) {
                    mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                    if (mAction == "new") {
                        NewClass();
                    } else {
                        CloseWindow(mini.getbyName("FName").getValue());
                    }
                }
                else {
                    mini.alert("" + ret.msg);
                }
                mini.getbyName("SaveInfo").enable();
            });
        }

        function FormShown() {
            mini.parse();
            loaded();
        }

        function loaded() {
            KindEditor.ready(function (K) {
                var editor1 = K.editor({
                    uploadJson: '../asp.net/upload_json.ashx?dirs=Mall&mSystemAppID=' + parent.window.getSystemAppID() + '&thumb=true',
                    fileManagerJson: '../asp.net/file_manager_json.ashx?dirs=Mall&mSystemAppID=' + parent.window.getSystemAppID(),
                    allowFileManager: true
                });

                K('#Image0').click(function () {
                    var url = $(this).attr('src');
                    if (url.toLowerCase() != "/content/images/noimage.jpg") {
                        var cfg = confirm("你确定要删除当前图片信息？");
                        if (!cfg) {
                            return;
                        }
                        else {
                            $(this).attr('src', "/content/Images/NoImage.jpg");
                            return;
                        }
                    }

                    editor1.loadPlugin('image', function () {
                        editor1.plugin.imageDialog({
                            imageUrl: K('#ImageFileUrl').val(),
                            clickFn: function (url, title, width, height, border, align) {
                                var path = ImageFilePath(url);
                                $("#Image0").attr('src', path);
                                mini.getbyName("FIcon").setValue(url);
                                editor1.hideDialog();
                            }
                        });
                    });
                });

            });
        }


        function ImageFilePath(url) {
            var result = "";
            $.ajax({
                url: "/GetItem/GetImageFilePath",
                data: { Url: url },
                type: "post",
                async: false,
                success: function (data) {
                    result = data;
                },
                failure: function () {
                    result = "";
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    return "";
                }
            });
            return result;
        }
    </script>

</form>

